<template>
  <div>
    <avue-crud
      :data="dataList"
      :option="option"
      :page="page"
      @refresh-change="getDataList"
      @row-update="rowUpdate"
      @row-save="rowSave"
      @row-del="rowDel"
      @search-change="searchChange"
      @search-reset="searchReset"
      @selection-change="selectionChange"
      @current-change="currentChange"
      @size-change="sizeChange"
      @on-load="getDataList"
    >
      <template slot-scope="scope" slot="decryptFileUrl">
        <el-tooltip
          v-if="
            scope.row.decryptFileUrl == null || scope.row.decryptFileUrl == ''
          "
          content="点击解密"
          placement="top"
          effect="dark"
        >
          <el-tag type="danger" size="small" @click="unrar">已加密</el-tag>
        </el-tooltip>
        <el-tooltip v-else content="点击查看" placement="top" effect="dark">
          <el-tag
            type="success"
            size="small"
            @click="view(scope.row.decryptFileUrl)"
            >查看</el-tag
          >
        </el-tooltip>
      </template>

      <template slot-scope="scope" slot="menu">
        <el-button
          type="text"
          size="small"
          icon="el-icon-finished"
          @click="secondaryQuotation(scope.row)"
          >二次报价</el-button
        >
      </template>
    </avue-crud>
  </div>
</template>

<script>
import { baseUrl } from "@/config/env";
import request from "@/router/axios";
import { getStore } from "@/util/store";

export default {
  name: "errLogs",
  data() {
    return {
      queryForm: {},
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      dataList: [],

      option: {
        menu: true,
        addBtn: false,
        editBtn: false,
        delBtn: false,
        viewBtn: false,
        page: true,
        border: true,
        expand: false,
        refreshBtn: true,
        headerAlign: "center",
        searchShow: true,
        searchMenuSpan: 6,
        column: [
          {
            label: "招标项目",
            prop: "zczxName",
            align: "center",
            solt: false,
            search: false,
          },
          {
            label: "投标文件",
            prop: "decryptFileUrl",
            align: "center",
            solt: false,
            search: false,
          },

          {
            label: "投标时间",
            align: "center",
            prop: "createTime",
            type: "datetime",
          },
        ],
      },
    };
  },
  created() {
    this.getDataList();
  },
  mounted() {},
  computed: {},
  props: [],
  methods: {
    getDataList() {
      let requestUrl =
        baseUrl +
        "/api/blade-ztb/tbrecords/myPage?current=" +
        this.page.currentPage +
        "&pageSize=" +
        this.page.pageSize;
      request({
        url: requestUrl,
        method: "get",
        params: this.queryForm,
      })
        .then((res) => {
          console.log("=res=", res);
          if (res.data.code == 200) {
            this.dataList = res.data.data.records;
            this, (this.page.total = res.data.data.total);
            console.log("=dataList =", this.dataList);
          }
        })
        .catch((e) => {
          console.error(e);
        });
    },

    openUploadDialog(row) {
      console.log("=openUploadDialog==", row);
      this.uploadForm.zczxId = row.id;
      this.uploadForm.glSpName = row.glSpName;
      console.log("==getStor==", getStore({ name: "token" }));
      this.uploadDialogVisible = true;
    },

    save() {
      const requestUrl = baseUrl + "/api/blade-ztb/tbrecords/save";
      request({
        url: requestUrl,
        method: "post",
        data: this.uploadForm,
      })
        .then((res) => {
          console.log("==res==", res);
          if (res.status == 200) {
            this.$message.success("数据保存成功");
            this.reset("uploadForm");
            this.fileList = [];
            this.getDataList();
            this.uploadDialogVisible = false;
          } else {
            this.$message.warning("数据保存失败");
          }
        })
        .catch((e) => {
          console.error(e);
        });
    },
    searchReset() {
      this.queryForm = {};
      this.getDataList();
    },
    searchChange(params) {
      this.queryForm = Object.assign(params, this.queryForm);
      console.log("=searchChange==queryForm==", this.queryForm);
      this.getDataList();
    },

    currentChange(currentPage) {
      this.page.currentPage = currentPage;
      this.getDataList();
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
      this.getDataList();
    },

    // 解压
    unrar() {
      this.$prompt("请输入密码", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        inputType: "password",
      })
        .then(({ value }) => {
          const requestUrl = baseUrl + "/api/blade-ztb/tbrecords/unrar";
          request({
            url: requestUrl,
          });
          console.log("准备解压:", value);
        })
        .catch(() => {
          console.info("取消输入");
        });
    },

    view(url) {
      this.$confirm("确认查看?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          window.open(url, "_blank");
        })
        .catch(() => {
          console.info("已取消");
        });
    },

    secondaryQuotation(row) {
      this.$prompt("请输入价格", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        inputType: "number",
      })
        .then(({ value }) => {
          const requestUrl = baseUrl + "/api/blade-ztb/tbrecords/secondaryQuotation";
          request({
            url: requestUrl,
            method:"post",
            data:{
              id:row.id,
              price:value
            }
          }).then(res=>{
            if(res.data.code == 200){
              this.$message.success("二次报价提交成功");
            } else {
              this.$message.warning("二次报价提交失败");
            }
          }).catch(e=>{
            console.error(e);
          });
        })
        .catch(() => {
          console.info("取消输入");
        });
    },
    reset(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>

<style lang="scss" scoped>
.code {
  font-size: 12px;
  display: block;
  font-family: monospace;
  white-space: pre;
  margin: 1em 0px;
}
</style>
